<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="ligerForm" action="">
				<div class="fieldset1 tabel_col clearFix">
					<div class="caption">
						<span class="title">移交详情&权证资料</span>						
					</div>
					<c:if test="${sign=='005' }">
					<div class="fieldBox col_100">
						<span class="sq-button sq-button-round" onclick="batchDownload();">下载解押材料</span>
					</div>
					</c:if>
					<c:if test="${sign=='004' }">
					<div class="fieldBox col_100">
						<span class="sq-button sq-button-round" onclick="batchDownload();">签收单及解押材料下载</span>
					</div>
					</c:if>
					<!--选择的移交数据展示-->
					<div class="fieldBox col_100">
						<div style="width: 98%; margin-left: 1%;">
							<div id="ligergrid_transfer" class="sq-grid"></div>
						</div>
					</div>
					<!--邮寄 -->
					<jsp:include page="../arcMgr/arcPostList.jsp" flush="true" />
					<c:if test="${sign=='002' || sign=='005' }"><!--只有省合同管理员可修改与添加邮寄信息-->
						<jsp:include page="../arcMgr/arcPostAdd.jsp" flush="true" />
					</c:if>						
				</div>
				<div class="btnsBox" style="text-align:center">
					<c:if test="${sign=='002' || sign=='005' }">
						<c:if test="${operate != 'view'}">
						<span id="saveBtn" class="sq-button sq-button-round" onclick="save();">保存</span>
						<!-- <span id="closeBtn" class="sq-button sq-button-round" onclick="Remove_navTab();">关闭</span> -->
						</c:if>
					</c:if>	
				</div>
				
			</form>
		</div>
	</div>
<script type="text/javascript">
	 	
	var grid;
	var mainId='${id}';	
	var sign = '${sign}';
	$(function() {
		$("#ligerForm").ligerForm({
			validate: true
		});
		
		initGrid();//初始化移交选择数据列表
    });
		
	//初始化列表
	function initGrid(){
		// 权证归档结清材料sign=04 解押材料盖章并邮寄sign=05
		if(sign && sign =='005'){
			$("#ligergrid_transfer").ligerGrid({
				url:'<%=path%>/archive/arcTransferMain/initTransferList.do',
				method:'get',
				parms:{'parentId':mainId},
				columns:[
					{ display: '承租人姓名', name: 'cstNm', minWidth: 100,
						render:function (rowdata, rowindex, value){
							return "<span title="+rowdata.cstNm+">"+rowdata.cstNm+"</span>";
						}
					},
					{ display: '合同号', name: 'contractNo', minWidth: 150,
						render:function (rowdata, rowindex, value){
							return "<span title="+rowdata.contractNo+">"+rowdata.contractNo+"</span>";
						}
					},
					{ display: '支付表号', name: 'paySchNo', minWidth: 160,
						render:function (rowdata, rowindex, value){
							return "<span title="+rowdata.paySchNo+">"+rowdata.paySchNo+"</span>";
						}
					},
					{ display: '结清时间', name: 'stlDt', minWidth: 50},
					{ display: '事业部', name: 'buOrgCdNm', minWidth: 60},
					{ display: '省公司', name: 'prOrgCdNm', minWidth: 90},
					{ display: '结清状态', name: 'prdStsCdNm', minWidth: 40,
						render:function (rowdata, rowindex, value){
							 var h="";
							 if(rowdata.prdStsCdNm=='正常'){
								 h='';
							 }else if(rowdata.prdStsCdNm=='已拖回'){
								 h='';
							 }else if(rowdata.prdStsCdNm=='拖回已转优车'){
								 h='';
							 }else{
								 h=rowdata.prdStsCdNm;
							 }
							 return h;
						 }
					},
					{ display: '交接单名称', name: 'arcReceiptName', minWidth: 40},
					{ display: '省公司档案编号', name: 'portfolioNumberProvince', minWidth: 30},
					{ display: '总部档案编号', name: 'portfolioNumber', minWidth: 30},
					{ display: '车架号', name: 'vin', minWidth: 30},
					{ display: '客户经理', name: 'cstMgrNm', minWidth: 30}
				],
				pageSize:30,
				pageSizeOptions:[30,40,50], //可指定每页页面大小
				record:'total',
				hideLoadButton:false,
				width:'100%',
				height:'100%',
				heightDiff:-2,
				isScroll: true,
				root: 'rows',
				hideLoadButton:false,
				frozen: false,
				//checkbox:true,//列表是否有选择框
				selectRowButtonOnly:true,//复选框模式时，是否只允许点击复选框才能选择行
				rownumbers:true,//列表是否有行号
				//选择行事件
				onSelectRow: function(rowdata, rowid, rowobj){
					
				},
				//取消选择行事件
				onUnSelectRow : function(rowdata, rowid, rowobj){
				}
			});
		}else if(sign && (sign =='004'||sign =='000')){
			$("#ligergrid_transfer").ligerGrid({
				url:'<%=path%>/archive/arcTransferMain/initTransferList.do',
				method:'get',
				parms:{'parentId':mainId},
				columns:[
					{ display: '承租人姓名', name: 'cstNm', minWidth: 100,
						render:function (rowdata, rowindex, value){
							return "<span title="+rowdata.cstNm+">"+rowdata.cstNm+"</span>";
						}
					},
					{ display: '合同号', name: 'contractNo', minWidth: 150,
						render:function (rowdata, rowindex, value){
							return "<span title="+rowdata.contractNo+">"+rowdata.contractNo+"</span>";
						}
					},
					{ display: '支付表号', name: 'paySchNo', minWidth: 160,
						render:function (rowdata, rowindex, value){
							return "<span title="+rowdata.paySchNo+">"+rowdata.paySchNo+"</span>";
						}
					},
					{ display: '结清时间', name: 'stlDt', minWidth: 50},
					{ display: '事业部', name: 'buOrgCdNm', minWidth: 60},
					{ display: '省公司', name: 'prOrgCdNm', minWidth: 90},
					{ display: '结清状态', name: 'prdStsCdNm', minWidth: 40,
						render:function (rowdata, rowindex, value){
							 var h="";
							 if(rowdata.prdStsCdNm=='正常'){
								 h='';
							 }else if(rowdata.prdStsCdNm=='已拖回'){
								 h='';
							 }else if(rowdata.prdStsCdNm=='拖回已转优车'){
								 h='';
							 }else{
								 h=rowdata.prdStsCdNm;
							 }
							 return h;
						 }	
					},
					{ display: '交接单名称', name: 'arcReceiptName', minWidth: 40},
					{ display: '省公司档案编号', name: 'portfolioNumberProvince', minWidth: 30},
					{ display: '总部档案编号', name: 'portfolioNumber', minWidth: 30},
					{ display: '车架号', name: 'vin', minWidth: 30},
					{ display: '客户经理', name: 'cstMgrNm', minWidth: 30}
				],
				pageSize:30,
				pageSizeOptions:[30,40,50], //可指定每页页面大小
				record:'total',
				hideLoadButton:false,
				width:'100%',
				height:'100%',
				heightDiff:-2,
				isScroll: true,
				root: 'rows',
				hideLoadButton:false,
				frozen: false,
				//checkbox:true,//列表是否有选择框
				selectRowButtonOnly:true,//复选框模式时，是否只允许点击复选框才能选择行
				rownumbers:true,//列表是否有行号
				//选择行事件
				onSelectRow: function(rowdata, rowid, rowobj){
					
				},
				//取消选择行事件
				onUnSelectRow : function(rowdata, rowid, rowobj){
					
				},
				 detail: {
		             height: 'auto',
		             onShowDetail: initWarrantGrid
		         }
			});
		}
		grid = liger.get("ligergrid_transfer");
		grid.setHeight(100);
		//grid.options.isSingleCheck = true;//列表是否为单选
	}
	//初始化权证资料列表
	function initWarrantGrid(row, detailPanel, callback) {
	 var gridBox = document.createElement('div');
	    $(gridBox).css('margin', 10);
	    $(detailPanel).css({
	        'padding': 10,
	        'box-sizing': 'border-box'
	    }).append(gridBox);
	    detailGrid = $(gridBox).ligerGrid({
	    	url:'<%=path%>/archive/arcTransferMain/initGridList.do',
	    	parms:{contractNo: row.contractNo, payListCode: row.paySchNo, arcLevel: "2",fileFlag:"3"},
	        method: 'get',
	        columns:[
	     			{ display: '权证类别', name: 'fileFlagNm', minWidth: 150, align: 'center', enabledSort: true},
	     			{ display: '权证名称', name: 'fileName', minWidth: 180, align: 'center', enabledSort: true},
	     			{ display: '资料类型', name: 'dossierTempNm', minWidth: 160, align: 'center', enabledSort: true},
	     			{ display: '存档份数', name: 'dossierCountT', minWidth: 160, align: 'center', enabledSort: true},
	     			{ display: '实际移交份数', name: 'transferCount', width: 90, align: 'center', enabledSort: true}
	     			
	     		],
	        root: 'rows',
	        hideLoadButton: true,
	        width: '100%',
	        height: 'auto',
	        isScroll: false,
	        rownumbers: true,  //显示序号
	        checkbox: false,
	        allowUnSelectRow: true,
	        alternatingRow: true,
	        onAfterShowData: callback,
	        frozen: false,
	        usePager: false
	    });
	    //ssign 003
	  if(sign=='004'){//权证归档结清资料
		  var gridBox1 = document.createElement('div');
		    $(gridBox1).css('margin', 10);
		    gridBox1.setAttribute("jieClass", "jieClass");
		    $(detailPanel).css({
		        'padding': 10,
		        'box-sizing': 'border-box'
		    }).append(gridBox1);
		      detailGrid1 = $(gridBox1).ligerGrid({
		    	url:'<%=path%>/archive/arcTransferMain/initJGridList.do',
		    	parms:{'transferMainId': row.id,'ssign':'${sign}'},
		        method: 'get',
		        columns:[
		     			{ display: '权证类别', name: 'fileFlagNm', minWidth: 150, align: 'center', enabledSort: true},
		     			{ display: '权证名称', name: 'fileName', minWidth: 180, align: 'center', enabledSort: true},
		     			{ display: '资料类型', name: 'dossierTempNm', minWidth: 100, align: 'center', enabledSort: true},
		     			{ display: '要求份数', name: 'dossierCount', minWidth: 100, align: 'center', enabledSort: true},
		     			{ display: '是否必须', name: 'ischoiceNm', minWidth: 100, align: 'center', enabledSort: true},
		     			{ display: '实际归档份数', name: 'transferNumber', width: 100, type: 'int'},
		     			{ display: '扫描件', name: 'scanAttcheList', width: 200, align: 'center', enabledSort: true,
		     				 render:function (rowdata, rowindex, value){
		     					var  h="";
		     					 h+='<span  class="upfiles" id="'+rowdata.id+'" fflag="1"  pkId="'+rowdata.id+'"  style="text-align:left"></span>';
     					    	if(rowdata.scanAttcheList){
		     						 var listl=rowdata.scanAttcheList;
		     						 for(var i=0;i<listl.length;i++){
		     							h+='<a target="_blank" href="'+listl[i].filePath+'">'+listl[i].fileNm+'</a>';
		     						 }
		     					 }	
		     					 return h;
		     				 }
		     			}
		     		],
		        root: 'rows',
		        hideLoadButton: true,
		        width: '100%',
		        height: 'auto',
		        heightDiff:-2,
		        isScroll: false,
		        rownumbers: true,  //显示序号
		        checkbox: false,
		        allowUnSelectRow: true,
		        alternatingRow: true,
		        onAfterShowData: callback,
		        enabledEdit: true,
		        frozen: false,
		        usePager: false
		    });   
	  }//签收单及解押资料回执上传
	}
	//保存
	function save(){
		
		var ligerForm = liger.get("ligerForm");
		if (!ligerForm.valid()) {
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
			return false; 
		}
		/* var flag='${flag}';// 只有省合同管理员或总部权证可以修改邮寄信息
		if(flag!=null && (flag=='003' || flag=='006')){
			if(!checkPost()){
				return ;
			}
		} */
		var sign='${sign}';// 只有省合同管理员或总部权证可以修改邮寄信息
		if(sign!=null && (sign=='006'||sign=='002' ||sign=='005' )){
			if(!checkPost()){
				return ;
			}
		}
		var data = ligerForm.getData();//主表数据
		//data["cjson"] = '${cjson}';
		//data["pjson"] = '${pjson}';
		//明细数据JSON.stringify(grid.getData());
		//alert(JSON.stringify(data));
		//alert(JSON.stringify(grid.getData()));
		//alert(JSON.stringify($("#ligerForm").serialize()));
		//console.log((JSON.stringify(data)));
		
		var wait_dialog = null;
		
		$.ajax({
			type: 'post',
			dataType: 'json',
			data: data,
			url: '<%=path%>/archive/arcTransferMain/modifyFlowN.do?sign=${sign}&id=${id}&paySchNo=${paySchNo}',
			beforeSend: function(){
				wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			},success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
						//if(id == "") {
							//Remove_navTab();//新增，关闭当前页面
						//}
					window.location.reload();
				}else{
					$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
				}
			},error:function (XMLHttpRequest, textStatus, errorThrown) { 
				wait_dialog.close();
				$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
			} 
		});
	}
		//查找人
		function searchBtn(){
			
			var wait_dialog = null;
			
			$.ajax({
				type: 'post',
				dataType: 'json',
				
				url: '<%=path%>/archive/arcMgrMain/searchBtn.do?idCardNM='+$("#idCardNM").val(),
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$("#idCard").val(msg.data.usrNm);
						$("#recipient").val(msg.data.refRlNm);
						$("#mobile").val(msg.data.mp);
					}else{
						$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					}
				},error:function (XMLHttpRequest, textStatus, errorThrown) { 
					wait_dialog.close();
					$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
				} 
			});
		}
	//是否显示解押材料 解押材料申请表
	function isShowInfor(val){
		if(val=='1'){
			$('#jieYaInfo').show();
		}else if(val=='0'){
			$('#jieYaInfo').hide();
		}
	}
	//签收单及解押材料下载批量下载
    function batchDownload() {
    	
		var actoinURL = '<%=path%>/archive/arcTransferMain/batchDownload.do';
    	var form = $("<form>");
        $('body').append(form);
        form.attr('style','display:none');
        form.attr('target','');
        form.attr('method','post');
        form.attr('action',actoinURL);
      
        var input = $('<input>');
        input.attr('type','hidden');
        input.attr('name','applyId');
        input.attr('value','${id}');
        form.append(input);
        
        var input1 = $('<input>');
        input1.attr('type','hidden');
        input1.attr('name','sign');
        input1.attr('value','${sign}');
        form.append(input1);
        
       
        form.submit();
    }
	
	</script>
</body>
</html>
